/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package seGobangClient.uiSystem2D;

import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
import seGobangResources.PathRes;

/**
 *
 * @author Leo
 */
public class MainScene
{

    
    private PathRes path = new PathRes();
    private MyButton ptp;
    private MyButton ptc;
    private MyButton online;
    private MyButton option;
    private MyButton cancel;
    private OptionScene OS;
    private WindowAdapter adapter;

    public void initMainUI(final JFrame container, final getpane mainPane)
    {

        container.setLayout(null);
        container.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

        try
        {
            mainPane.imgpath = path.getPath("Texture/Entrance");
            mainPane.setLocation(0, 0);
            mainPane.setLayout(null);
            mainPane.setSize(container.getWidth(), container.getHeight());
            container.getContentPane().add(mainPane);

            ptp = new MyButton("Texture/MainMenu/1A", "Texture/MainMenu/1B", 140, 40);
            ptc = new MyButton("Texture/MainMenu/2A", "Texture/MainMenu/2B", 140, 40);
            online = new MyButton("Texture/MainMenu/3A", "Texture/MainMenu/3B", 140, 40);
            option = new MyButton("Texture/MainMenu/4A", "Texture/MainMenu/4B", 140, 40);
            cancel = new MyButton("Texture/MainMenu/5A", "Texture/MainMenu/5B", 140, 40);
            
            ptp.setSize(140, 40);
            ptp.setLocation(640, 0);
            ptc.setSize(140, 40);
            ptc.setLocation(640, 40);
            online.setSize(140, 40);
            online.setLocation(640, 80);
            option.setSize(140, 40);
            option.setLocation(640, 120);
            cancel.setSize(140, 40);
            cancel.setLocation(640, 160);
            mainPane.add(ptp);
            mainPane.add(ptc);
            mainPane.add(online);
            mainPane.add(option);
            mainPane.add(cancel);
           
            option.setValid(false);
            ptp.setValid(false);
            ptc.setValid(false);
            online.setValid(false);
            cancel.setValid(false);
            new Timer().schedule(new TimerTask()
            {

                public void run()
                {
                    Point p = new Point();
                    ptp.getLocation(p);
                    p.x -= 3;
                    ptp.setLocation(p);
                    online.getLocation(p);
                    p.x -= 3;
                    online.setLocation(p);
                   
                    option.getLocation(p);
                    p.x -= 3;
                    option.setLocation(p);
                    ptc.getLocation(p);
                    p.x -= 3;
                    ptc.setLocation(p);
                    cancel.getLocation(p);
                    p.x -= 3;
                    cancel.setLocation(p);
                    if (p.x <= 495)
                    {
                        option.setValid(true);
                        ptp.setValid(true);
                        ptc.setValid(true);
                        online.setValid(true);
                        cancel.setValid(true);
                        super.cancel();
                    }
                }
            }, 0, 10);
            ptp.addActionListener(new ActionListener()
            {

                public void actionPerformed(ActionEvent e)
                {
                    option.setValid(false);
                    ptp.setValid(false);
                    ptc.setValid(false);
                    online.setValid(false);
                    cancel.setValid(false);
                    new Timer().schedule(new TimerTask()
                    {

                        public void run()
                        {
                            Point p = new Point();
                            ptc.getLocation(p);
                            p.x += 3;
                            ptc.setLocation(p);
                            online.getLocation(p);
                            p.x += 3;
                            online.setLocation(p);
                            option.getLocation(p);
                            p.x += 3;
                            option.setLocation(p);
                            cancel.getLocation(p);
                            p.x += 3;
                            cancel.setLocation(p);
                            if (p.x >= 640)
                            {
                                SceneManager.MyCurrentController.doEvent("ChangeSceneToLocalGame", null);
                                // ptpGS = new PtoPGameScene();
                                // ptpGS.initGameUI(container, mainPane);
                                /*mainPane.remove(ptc);
                                mainPane.remove(online);
                                mainPane.remove(option);
                                mainPane.remove(cancel);
                                ptc = null;
                                online = null;
                                option = null;
                                cancel = null;*/
                                //System.gc();
                                super.cancel();
                            }
                        }
                    }, 0, 10);
                }
            });
            ptc.addActionListener(new ActionListener()
            {

                public void actionPerformed(ActionEvent e)
                {
                    option.setValid(false);
                    ptp.setValid(false);
                    ptc.setValid(false);
                    online.setValid(false);
                    cancel.setValid(false);
                    new Timer().schedule(new TimerTask()
                    {

                        public void run()
                        {
                            Point p = new Point();
                            ptp.getLocation(p);
                            p.x += 3;
                            ptp.setLocation(p);
                            online.getLocation(p);
                            p.x += 3;
                            online.setLocation(p);
                            option.getLocation(p);
                            p.x += 3;
                            option.setLocation(p);
                            cancel.getLocation(p);
                            p.x += 3;
                            cancel.setLocation(p);
                            if (p.x >= 640)
                            {
                                ptc.getLocation(p);
                                p.y -= 3;
                                ptc.setLocation(p);
                                if (p.y <= 0)
                                {
                                    SceneManager.MyCurrentController.doEvent("ChangeSceneToAIGame", null);
                                    /*mainPane.remove(ptp);
                                    mainPane.remove(online);
                                    mainPane.remove(option);
                                    mainPane.remove(cancel);
                                    ptp = null;
                                    online = null;
                                    option = null;
                                    cancel = null;*/
                                    super.cancel();
                                }
                            }
                        }
                    }, 0, 10);
                }
            });
            online.addActionListener(new ActionListener()
            {

                public void actionPerformed(ActionEvent e)
                {
                    option.setValid(false);
                    ptp.setValid(false);
                    ptc.setValid(false);
                    online.setValid(false);
                    cancel.setValid(false);
                    new Timer().schedule(new TimerTask()
                    {

                        public void run()
                        {
                            Point p = new Point();
                            ptp.getLocation(p);
                            p.x += 3;
                            ptp.setLocation(p);
                            ptc.getLocation(p);
                            p.x += 3;
                            ptc.setLocation(p);
                            option.getLocation(p);
                            p.x += 3;
                            option.setLocation(p);
                            cancel.getLocation(p);
                            p.x += 3;
                            cancel.setLocation(p);
                            if (p.x >= 640)
                            {
                                online.getLocation(p);
                                p.y -= 3;
                                online.setLocation(p);
                                if (p.y <= 0)
                                {
                                    SceneManager.MyCurrentController.doEvent("ChangeSceneToOnlineHall", null);
                                   /* mainPane.remove(ptc);
                                    mainPane.remove(option);
                                    mainPane.remove(ptp);
                                    mainPane.remove(cancel);
                                    ptc = null;
                                    option = null;
                                    ptp = null;
                                    cancel = null;*/
                                    super.cancel();
                                }
                            }
                        }
                    }, 0, 10);
                }
            });
            option.addActionListener(new ActionListener()
            {

                public void actionPerformed(ActionEvent e)
                {
                    option.setValid(false);
                    ptp.setValid(false);
                    ptc.setValid(false);
                    online.setValid(false);
                    cancel.setValid(false);
                    new Timer().schedule(new TimerTask()
                    {

                        public void run()
                        {
                            Point p = new Point();
                            ptp.getLocation(p);
                            p.x += 3;
                            ptp.setLocation(p);
                            online.getLocation(p);
                            p.x += 3;
                            online.setLocation(p);
                            ptc.getLocation(p);
                            p.x += 3;
                            ptc.setLocation(p);
                            cancel.getLocation(p);
                            p.x += 3;
                            cancel.setLocation(p);
                            if (p.x >= 640)
                            {
                                option.getLocation(p);
                                p.y -= 3;
                                option.setLocation(p);
                                if (p.y <= 0)
                                {
                                    SceneManager.MyCurrentController.doEvent("ChangeSceneToConfigMenu", null);
                                   /* mainPane.remove(ptc);
                                    mainPane.remove(online);
                                    mainPane.remove(ptp);
                                    mainPane.remove(cancel);
                                    ptc = null;
                                    online = null;
                                    ptp = null;
                                    cancel = null;*/
                                    super.cancel();
                                }
                            }
                        }
                    }, 0, 10);
                }
            });
            cancel.addActionListener(new ActionListener()
            {

                public void actionPerformed(ActionEvent e)
                {
                    SceneManager.MyCurrentController.doEvent("ExitGame", null);
                }
            });
            
        } catch (Exception e)
        {
            
        }
        container.repaint();
    }
}
